package com.wowoai.common.response;

import com.wowoai.common.enums.ResponseEnum;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

@Data
//@Builder
public class ResponseVO<T> implements Serializable {

    private boolean isSuccess;
    private Integer errCode;
    private String errMessage;
    private T data;

    public ResponseVO() {
    }

    public static <T> ResponseVO<T> fail(Integer errCode, String errMessage) {
        ResponseVO<T> response = new ResponseVO<>();
        response.setSuccess(Boolean.FALSE);
        response.setErrCode(errCode);
        response.setErrMessage(errMessage);
        return response;
    }

    public static <T> ResponseVO<T> fail(ResponseEnum errorCodeI) {
        ResponseVO<T> ResponseVO = new ResponseVO<>();
        ResponseVO.setSuccess(false);
        ResponseVO.setErrCode(errorCodeI.getCode());
        ResponseVO.setErrMessage(errorCodeI.getDesc());
        return ResponseVO;
    }
    public static <T> ResponseVO<T> fail(String errMessage) {
        ResponseVO<T> ResponseVO = new ResponseVO<>();
        ResponseVO.setSuccess(false);
        ResponseVO.setErrCode(ResponseEnum.BUSINESS_FAIL.getCode());
        ResponseVO.setErrMessage(errMessage);
        return ResponseVO;
    }

    public static <T> ResponseVO<T> fail(ResponseEnum errorCodeI, String errMessage) {
        ResponseVO<T> ResponseVO = new ResponseVO<>();
        ResponseVO.setSuccess(false);
        ResponseVO.setErrCode(errorCodeI.getCode());
        ResponseVO.setErrMessage(errMessage);
        return ResponseVO;
    }

    public static <T> ResponseVO<T> fail(ResponseEnum errorCodeI, String errMessage, T data) {
        ResponseVO<T> ResponseVO = new ResponseVO<>();
        ResponseVO.setSuccess(false);
        ResponseVO.setErrCode(errorCodeI.getCode());
        ResponseVO.setErrMessage(errMessage);
        ResponseVO.setData(data);
        return ResponseVO;
    }

    public static <T> ResponseVO<T> fail(ResponseEnum errorCodeI, T data) {
        ResponseVO<T> ResponseVO = new ResponseVO<>();
        ResponseVO.setSuccess(false);
        ResponseVO.setErrCode(errorCodeI.getCode());
        ResponseVO.setErrMessage(errorCodeI.getDesc());
        ResponseVO.setData(data);
        return ResponseVO;
    }

    public static <T> ResponseVO<T> success(T data) {
        ResponseVO<T> singleResponseVO = new ResponseVO<>();
        singleResponseVO.setSuccess(true);
        singleResponseVO.setData(data);
        return singleResponseVO;
    }
}
